<?php
include('common_include.php');

$username = $_POST["username"];
$password = $_POST["password"];

/*
$username='admin';
$password='adfsdf';
*/

$dao = new SQLitePersistence();

if ($username != '' && $password != '') {
	try {
		if ($dao->authenticate($username, $password)) {
			echo date("Y-m-d"). " " . date("H:i:s");
			$_SESSION['loginTime'] = date("Y-m-d H:i:s");
			usleep(5000);
			header("Location: mainLayout.php");
		} else {
			header("Location: login.php?error=Invalid username and password");
		}
	} catch (PersistenceException $e) {
		Logger::logError($e);
	}
} else {
	Logger::logInfo('Javascript injection is disabled');
}

unset($dao);

?>